Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming


Calling methods from outside a class

You can access PUBLIC methods from outside the class hierarchy of a given object by using an object reference to qualify the method name. When you invoke a PUBLIC method on an object that is overridden in the object’s class hierarchy, Progress invokes the method in the bottom-most subclass that defines the method. There is no access to PRIVATE or PROTECTED methods from outside the class hierarchy.

This is the syntax to invoke a method from outside a class instance:

Syntax
[ return-value = ]  
    object-reference:method-name ( [ parameter [ , parameter ] ... ] ) . 

Element descriptions for this syntax diagram follow:

return-var

The name of the variable to put the return value into.

object-reference

An object reference for a class, a super class, or an interface that the class implements.

method-name

The name of a PUBLIC method defined somewhere in the class hierarchy of object-reference.

[ parameter [ , parameter ] ... ]

The parameters of the method. For more information on the syntax of parameter, see the “Parameter passing syntax” reference entry in OpenEdge Development: Progress 4GL Reference .

The compiler verifies that the parameters used in the method invocation are consistent with parameters defined for the method. The compiler verifies that the number, mode and data type of these parameters match exactly. There is no implicit conversion of any data types when passing method parameters. However, Progress does allow a dynamic temp-table or ProDataSet to be passed to static temp-table or ProDataSet parameter (respectively), and similarly for passing a static temp-table or ProDataSet to a corresponding dynamic temp-table or ProDataSet parameter.

Note: If the parameter is a class or interface type, the parameter is passed by value as an object reference. The effect of passing an object reference parameter is identical to assigning one object reference to another. For more information, see the "Defining an object reference as a parameter" section.

The following example shows two sample classes, where a method in acme.myObjs.CustObj calls the public Alert( ) method in an instance of acme.myObjs.Common.ErrorObj that is created for acme.myObjs.CustObj:

CLASS acme.myObjs.CustObj INHERITS acme.myObjs.Common.CommonObj  
                          IMPLEMENTS acme.myObjs.Interfaces.IBusObj: 
    ... 
    DEFINE PRIVATE VARIABLE rError  
        AS CLASS acme.myObjs.Common.ErrorObj NO-UNDO. 
    ... 
    CONSTRUCTOR PUBLIC CustObj( ): 
        ... 
        rError = ErrorHandler("acme.MyObjs.CustObj"). 
    END CONSTRUCTOR. 
    METHOD PUBLIC VOID CheckCredit( ): 
        DEFINE VARIABLE rCreditObj AS CLASS acme.myObjs.CreditObj NO-UNDO. 
        rCreditObj = NEW acme.myObjs.CreditObj( ). 
        IF VALID-OBJECT(rCreditObj) THEN DO: 
            FOR EACH Customer where CustNum < 15: 
                IF Customer.CreditLimit < 15000 THEN DO: 
                    rError:Alert("There is a problem with this Customer"). 
                    rCreditObj:creditAlert(Customer.CustNum). 
                END. 
            END. 
            DELETE OBJECT rCreditObj. 
        END. 
        ELSE DO: 
            rError:Alert("Unable to check credit"). 
        END. 
    END METHOD. 
    ... 
END CLASS. 

In this case, the rError object reference is a private class variable that is initialized to an instance of acme.myObjs.Common.ErrorObj returned from the ErrorHandler( ) method of the acme.myObjs.Common.CommonObj super class. (See the listing for this super class in the "Calling methods from inside a class" section). This acme.myObjs.Common.ErrorObj instance holds error information specifically for the acme.myObjs.CustObj class that can be accessed using the Alert( ) method implemented as follows:

CLASS acme.myObjs.Common.ErrorObj: 
    DEFINE PRIVATE VARIABLE ObjType AS CHARACTER NO-UNDO. 
    CONSTRUCTOR PUBLIC ErrorObj (INPUT rObjType AS CHARACTER): 
        ObjType = rObjType. 
    END CONSTRUCTOR. 
   
    METHOD PUBLIC VOID Alert (INPUT ErrorString AS CHARACTER): 
        MESSAGE "Error in " ObjType "!" SKIP 
                ErrorString VIEW-AS ALERT-BOX. 
    END METHOD. 
END CLASS. 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095